package com.lvmama.pangolin.controller;


import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.lvmama.pangolin.common.MD5Util;
import com.lvmama.pangolin.common.StringTools;
import com.lvmama.pangolin.entity.ResultMsg;
import com.lvmama.pangolin.entity.lmm.LMMCareProduct;
import com.lvmama.pangolin.lmm.service.LMMCareProductService;
import com.lvmama.pangolin.util.SpringContextUtil;


@RestController  
@RequestMapping("syn") 
public class CareProductController
{
	@Autowired
	LMMCareProductService productService;
	
	private static Logger log = Logger.getLogger(CareProductController.class);
	
	@RequestMapping("getNewProd")  
	public Object  queryNewProduct(String key,String time)
	{
		log.info("获取产品信息开始！");
		ResultMsg msg = new ResultMsg();
		msg.setSuccess("fail");
		msg.setMessage("get product data error!");
		msg.setCode("1");
		try
		{
			if(productService == null )
			{
				productService = (LMMCareProductService) SpringContextUtil.getBean(LMMCareProductService.class);
			}
			if(StringTools.isValid(key) && StringTools.isValid(time))
			{
				String authKey = MD5Util.encode(time);
				if(key.equals(authKey))
				{
					Timestamp ts = new Timestamp(Long.parseLong(time));
					Map<String,Object> param = new HashMap<String,Object>();
					param.put("updateTime", ts);
					List<LMMCareProduct> careList = productService.queryProductbyTime(param);
					msg.setData(careList);
					msg.setSuccess("success");
					msg.setMessage("get product data success!");
					msg.setCode("0");
					
					
				}
				
			}
			
		}catch (Exception e)
		{
			log.error("获取产品信息失败！",e);
		}
		log.info("获取产品信息结束！");
		return msg;
		
	}
}
